//
//  L0EntryTableAppDelegate.m
//  L0EntryTable
//
//  Created by ∞ on 18/07/08.
//  Copyright Emanuele Vulcano 2008. All rights reserved.
//

#import "L0EntryTableAppDelegate.h"

@implementation L0EntryTableAppDelegate

@synthesize window;
@synthesize navigationController;


- (id)init {
	if (self = [super init]) {
		// 
	}
	return self;
}


- (void)applicationDidFinishLaunching:(UIApplication *)application {
	
	L0EntryCell* uno = [L0EntryCell new];
	uno.text = @"1";
	L0EntryCell* due = [L0EntryCell new];
	due.text = @"2";
	
	L0EntrySection* section = [L0EntrySection new];
	NSMutableArray* cells = [section mutableArrayValueForKey:@"cells"];
	[cells addObject:uno];
	[cells addObject:due];
	[cells addObject:textFieldCell];
	[cells addObject:textFieldCell2];
	[cells addObject:dateCell];
	
	[[controller mutableArrayValueForKey:@"sections"] addObject:section];
	
	[uno release];
	[due release];
	[section release];
	// [controller.tableView reloadData]; // TODO
	
	// Configure and show the window
	[window addSubview:[navigationController view]];
	[window makeKeyAndVisible];
}


- (void)applicationWillTerminate:(UIApplication *)application {
	// Save data if appropriate
}


- (void)dealloc {
	[navigationController release];
	[window release];
	[super dealloc];
}

- (IBAction) addSection {
	static int x = 3;
	L0EntryCell* cell = [L0EntryCell new];
	cell.text = [NSString stringWithFormat:@"%d", x];

	L0EntryCell* cell2 = [L0EntryCell new];
	cell2.text = [NSString stringWithFormat:@"%d", x];
	
//	L0EntrySection* section = [L0EntrySection new];
//	[section insertObject:cell inCellsAtIndex:0];
//	[cell release];
	
	L0EntrySection* section = [controller objectInSectionsAtIndex:0];
//	[section insertObjects:[NSArray arrayWithObjects:cell, cell2, nil] inCellsStartingAtIndex:[section countOfCells]];
	
	[controller.tableView beginUpdates];
	[section insertObject:cell inCellsAtIndex:[section countOfCells] - 1];
	[section insertObject:cell2 inCellsAtIndex:[section countOfCells] - 1];
	[controller.tableView endUpdates];
	
	[controller.tableView flashScrollIndicators];
		
	x++;
}

@end
